//
//  YZSecurityVerifyVC.m
//  VET
//
//  Created by 刘文靖 on 2018/6/29.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "YZSecurityVerifyVC.h"
#import "YZGradientBtn.h"
#import "YZUser.h"
#import "NSString+Category.h"
#import "YZPersonalVM.h"
#import "YZResetPasswordVC.h"
@interface YZSecurityVerifyVC ()
@property (weak, nonatomic) IBOutlet UILabel *mobileDescLabel;
@property (weak, nonatomic) IBOutlet UITextField *verCodeTF;
@property (weak, nonatomic) IBOutlet YZGradientBtn *verCodeButton;
@property (weak, nonatomic) IBOutlet YZGradientBtn *nextButton;
@property (copy, nonatomic) NSString *mobile;
@property (strong, nonatomic) YZPersonalVM *viewModel;
@end

@implementation YZSecurityVerifyVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"安全验证";
    self.mobile = [YZUser sharedInstance].phone;
    self.mobileDescLabel.text = [NSString stringWithFormat:@"设置密码需先验证您的手机号码%@",[NSString getSecrectStringWithPhoneNumber:self.mobile]];
    RACSignal *verCodeSignal = [self.verCodeTF.rac_textSignal map:^id(NSString *str) {
        return @(str.length);
    }];
    RAC(self.nextButton, enabled) = verCodeSignal;
}
- (IBAction)verCodeButtonClicked {
    @weakify(self)
    [[self.viewModel requestMessageForPWD:self.mobile] subscribeNext:^(id  _Nullable x) {
    } completed:^{
        @strongify(self)
        [self.verCodeButton startCount:60];
    }];
}
- (IBAction)nextButtonClicked {
    YZResetPasswordVC *resetPWDVC =  [[UIStoryboard storyboardWithName:@"personalCenter" bundle:nil] instantiateViewControllerWithIdentifier:@"YZResetPasswordVC"];
    resetPWDVC.verCode = self.verCodeTF.text;
    [self.navigationController pushViewController:resetPWDVC animated:YES];
}

- (YZPersonalVM *)viewModel{
    if (!_viewModel) {
        _viewModel = [[YZPersonalVM alloc] init];
    }
    return _viewModel;
}

@end
